package cn.jbooter.ctx.autoconfigure.container;

import org.springframework.context.EnvironmentAware;
import org.springframework.core.env.Environment;
import cn.jbooter.coms.utils.StringUtil;

/**
 * spring容器管理的配置信息获取
 * @author HeJian
 *
 */
public class EnvironmentUtils implements EnvironmentAware{

	private static Environment environment;

	public static Environment getEnvironment() {
		return EnvironmentUtils.environment;
	}
	
	@Override
	public void setEnvironment(Environment environment) {
		EnvironmentUtils.environment = environment;
	}
	
	public static String get(String name) {
		String property = environment.getProperty(name);
		return property;
	}
	
	public static Boolean getBoolean(String name) {
		String string = get(name);
		if(StringUtil.isEmpty(string)) {
			return null;
		}
		Boolean valueOf = Boolean.valueOf(string);
		return valueOf;
	}
	
	public static Integer getInteger(String name) {
		String string = get(name);
		if(StringUtil.isEmpty(string)) {
			return null;
		}
		Integer valueOf = Integer.valueOf(string);
		return valueOf;
	}

	
}